<?php
declare (strict_types = 1);
namespace app\admin\controller;

use think\Request;
use think\facade\{View};
use think\exception\ValidateException;

use app\common\model\{Star, TeamRewardRule, Achiev};
// use app\common\validate\{ApplyValidate};

/** 等级和奖励 */
class RewardController extends BaseController
{
    /**
     * 渲染等级列表页面
     */
    public function star_list()
    {
        return view();
    }

    /**
     * 获取等级数据列表
     */
    public function star_data()
    {
        $starModel = new Star();
        $list = $starModel->getList([], 0, 0, 0, '*', 'id');

        if($list['code'] != 'ok'){
            $this->error_back('暂无数据~');
        }

        $this->success_back('ok', $list['data']);
    }

    /**
     * 等级数据编辑
     */
    public function star_edit()
    {
        $data = input('');

        $starModel = new Star();
        $flag = $starModel->edit(['id' => $data['id'], $data['field'] => $data['value']]);

        if($flag['code'] != 'ok'){
            $this->error_back($flag['msg']);
        }

        $this->success_back('编辑成功');
    }




    /**
     * 渲染团队规则列表页面
     */
    public function team_list()
    {
        return view();
    }

    /**
     * 获取团队规则数据列表
     */
    public function team_data()
    {
        $teamModel = new TeamRewardRule();
        $list = $teamModel->getList([], 0, 0, 0, '*', 'id');

        if($list['code'] != 'ok'){
            $this->error_back('暂无数据~');
        }

        $this->success_back('ok', $list['data']);
    }

    /**
     * 团队规则数据编辑
     */
    public function team_edit()
    {
        $data = input('');

        $teamModel = new TeamRewardRule();
        $flag = $teamModel->edit(['id' => $data['id'], $data['field'] => $data['value']]);

        if($flag['code'] != 'ok'){
            $this->error_back($flag['msg']);
        }

        $this->success_back('编辑成功');
    }




    /**
     * 渲染业绩规则列表页面
     */
    public function achiev_list()
    {
        return view();
    }

    /**
     * 获取业绩规则数据列表
     */
    public function achiev_data()
    {
        $achievModel = new Achiev();
        $list = $achievModel->getList([], 0, 0, 0, '*', 'id');

        if($list['code'] != 'ok'){
            $this->error_back('暂无数据~');
        }

        $this->success_back('ok', $list['data']);
    }

    /**
     * 业绩规则数据编辑
     */
    public function achiev_edit()
    {
        $data = input('');

        $achievModel = new Achiev();
        $flag = $achievModel->edit(['id' => $data['id'], $data['field'] => $data['value']]);

        if($flag['code'] != 'ok'){
            $this->error_back($flag['msg']);
        }

        $this->success_back('编辑成功');
    }
}
